package ${package}.${packageServiceImpl};

<#assign upClassName=className?cap_first>
import ${package}.${packageService}.I${upClassName}Service;
import ${package}.${packageEntity}.${upClassName};
import ${package}.${packageDao}.I${upClassName}Dao;
import com.syswin.systoon.framework.constant.CoreConstants;
import com.syswin.systoon.framework.exception.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ${upClassName}ServiceImpl implements I${upClassName}Service{

    private static final Logger logger = LoggerFactory.getLogger(${upClassName}ServiceImpl.class);

    @Autowired
    I${upClassName}Dao ${className}Dao;

    @Override
    public void create(${upClassName} ${className}) {
        if(null == ${className}){
            throw new BusinessException(CoreConstants.REQUEST_ERROR_PARAMS,"输入参数为空", false);
        }
        Date now = new Date();
        ${className}.setCreateTime(now);
        ${className}.setUpdateTime(now);
        ${className}Dao.insert(${className});
    }

    @Override
    public void modifyById(${upClassName} ${className}) {
        if(null == ${className}){
            throw new BusinessException(CoreConstants.REQUEST_ERROR_PARAMS, "输入参数为空",false);
        }
        ${className}.setUpdateTime(new Date());
        ${className}Dao.updateById(${className});
    }

    @Override
    public void deleteById(Long id) {
        if(null == id){
            throw new BusinessException(CoreConstants.REQUEST_ERROR_PARAMS, "输入参数为空", false);
        }
        ${upClassName} record = new ${upClassName}();
        record.setId(id);
        record.setDeleteFlag(true);
        record.setUpdateTime(new Date());
        int count = ${className}Dao.updateById(record);
        if(count < 1){
            logger.error("${upClassName}ServiceImpl.deleteById方法执行失败,输入参数:{}",id);
            throw new BusinessException(CoreConstants.REQUEST_ERROR_PARAMS, "操作失败", false);
        }
    }

    @Override
    public ${upClassName} get${upClassName}ById(Long id) {
        ${upClassName} result = null;
        if(null == id){
            return result;
        }
        result = ${className}Dao.getById(id);
        return result;
    }

    @Override
    public List<${upClassName}> findList(${upClassName} ${className}) {
        return ${className}Dao.findList(${className});
    }
}